# The xv6 kernel starts executing in this file. This file is linked with
# the kernel C code, so it can refer to kernel symbols such as main().
# The boot block (bootasm.S and bootmain.c) jumps to entry below.
# xv6内核在此处开始执行 本文件链接到内核的c代码，因此他可以引导内核符号例如 main（）函数
# 这个boot块(bootasm.S and bootmain.c)跳转到下面的entry    AT&T格式

# Multiboot header, for multiboot boot loaders like GNU Grub.
# http://www.gnu.org/software/grub/manual/multiboot/multiboot.html
#
# Using GRUB 2, you can boot xv6 from a file stored in a
# Linux file system by copying kernel or kernelmemfs to /boot
# and then adding this menu entry:
#
# menuentry "xv6" {
# 	insmod ext2
# 	set root='(hd0,msdos1)'
# 	set kernel='/boot/kernel'
# 	echo "Loading ${kernel}..."
# 	multiboot ${kernel} ${kernel}
# 	boot
# }

#include "asm.h"
#include "memlayout.h"
#include "mmu.h"
#include "param.h"

# Multiboot header.  Data to direct multiboot loader. .globl在xv6启动处有解释 .long定于一个空间并储存
.p2align 2
.text
.globl multiboot_header
multiboot_header:
  #define magic 0x1badb002
  #define flags 0
  .long magic
  .long flags
  .long (-magic-flags)

# By convention, the _start symbol specifies the ELF entry point.
# Since we haven't set up virtual memory yet, our entry point is
# the physical address of 'entry'. 
# 按照惯例，_start符号指定ELF入口点，因为我们还没有设置虚拟内存，所以我们的入口点是“entry”的物理地址
.globl _start
_start = V2P_WO(entry)

# Entering xv6 on boot processor, with paging off.在启动处理器上进入xv6，并关闭分页
.globl entry
entry:
  # Turn on page size extension for 4Mbyte pages   将cr4给到eax再orl再赋给cr4
  movl    %cr4, %eax
  orl     $(CR4_PSE), %eax
  movl    %eax, %cr4
  # Set page directory  将 `entrypgdir` 的物理地址载入到控制寄存器 `%cr3`
  movl    $(V2P_WO(entrypgdir)), %eax
  movl    %eax, %cr3          
  # Turn on paging.  设置控制寄存器 `%cr0` 中的标志位 `CR0_PG`
  movl    %cr0, %eax
  orl     $(CR0_PG|CR0_WP), %eax
  movl    %eax, %cr0

  # Set up the stack pointer. 建立栈指针为C语言做准备
  movl $(stack + KSTACKSIZE), %esp

  # Jump to main(), and switch to executing at
  # high addresses. The indirect call is needed because
  # the assembler produces a PC-relative instruction
  # for a direct jump.   跳转到main执行 需要间接调用，因为汇编器为直接跳转生成PC相关指令
  mov $main, %eax   
  jmp *%eax

.comm stack, KSTACKSIZE
